$(function () {
    $('#passwordForm').bootstrapValidator({
        message: 'This value is not valid',
        fields: {
            newPassword: {
                validators: {
                    notEmpty: {
                        message: '新密码不能为空'
                    },identical: {
                        field: 'confirmPassword',
                        message: '新密码与确认密码不一致！'
                    }
                }
            },
            confirmPassword: {
                validators: {
                    notEmpty: {
                        message: '确认密码不能为空'
                    },identical: {
                        field: 'newPassword',
                        message: '新密码与确认密码不一致！'
                    }
                }
            }
        },
        submitHandler: function (validator, form, submitButton) {
            changePassword();
        }
    });

})



function changePassword() {
        $.ajax({
            url: "/login/changePassword",
            type: "post",
            data: {
                "password": $("#newPassword").val()
            },
            success: function (data) {
                if (data.code == 0){
                    window.location.href="/login/logout"
                }else {
                    layer.msg(data.msg)
                }
            },
            error: function (data) {

            }
        });
}



function resetPasswordModal() {
    document.getElementById("passwordForm").reset();
    $('#passwordForm').data('bootstrapValidator').resetForm(true);
}



